package com.link.base.base.receiptrecord.controller;

import com.link.base.base.receiptrecord.model.ReceiptRecord;
import com.link.base.base.receiptrecord.service.ReceiptRecordService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 程厚霖
 * @date 2018-07-20
 * @comments 开票记录
 */
@Controller
@RequestMapping("/link/receiptRecord")
public class ReceiptRecordController extends BasicController<ReceiptRecord> {

    @Resource
    private ReceiptRecordService receiptRecordService;

    @Override
    public BasicService<ReceiptRecord> getBasicService() throws Exception {
        return receiptRecordService;
    }

    @Override
    public void beforInsert(ReceiptRecord entity, HttpServletRequest request) throws Exception {
//        SaleOrder saleOrder = saleOrderService.queryOneById(entity.getOrderId());
//        List<SaleOrderItem> saleOrderItem = saleOrderItemService.querylistByOrderId(entity.getOrderId());
//        ReceiptRecord queryParam = new ReceiptRecord();
//        queryParam.setPageFlag(false);
//        queryParam.setOrderId(entity.getOrderId());
//        List<ReceiptRecord> receiptRecordList = receiptRecordService.queryByExamplePage(queryParam);
//        Double sum = receiptRecordList.stream()
//                .mapToDouble(p -> Double.parseDouble(p.getReceiptAmount()))
//                .sum() + Double.parseDouble(entity.getReceiptAmount());
//        if (!"CreditInvoice".equals(entity.getReceiptType())) {
//            if (sum.doubleValue() > saleOrder.getOrderTotalAmount().doubleValue()) {
//                throw new RuntimeException("开票已完成，不可重复开票");
//            }
//        }
    }
}
